net: add createPipe() and createSocketPair() - #65094
Conversation
|
I dont think we should create a new module |
|
+1, there's no justification for a new top-level module. |
83d8402 to
db5d657
Compare
|
Yep. I'll move it to net. |
|
I also pushed a small stacked follow-up branch that explores the adjacent kingces95/node@create-pipe...create-socket-pair My immediate use case is The idea is that The follow-up has child-process support for fd |
|
I folded the socket-pair follow-up into the main change. The updated version keeps both APIs in
This should make the PR easier to review as one coherent “parent-owned OS endpoints” feature. The removed sketch is preserved here as a userland workbook/example of the style of shell-like stream composition this API is meant to enable: https://gist.github.com/kingces95/1e024a1e987ef3956c7ae3513e468c64 |
3621fab to
3c6c2d0
Compare
Signed-off-by: Chris King <kingces95@gmail.com>
|
I landed on a single coherent
So the PR is no longer “just create pipe.” It is a parent-owned OS endpoint proposal: pipes for directional stdio leasing, socket pairs for duplex cross-process communication. |
Adds a
node:pipemodule withcreatePipe(), returning a readable and writable endpoint owned by the parent process.The endpoints may be passed to
child_process.spawn()stdio. This lets the parent lend a pipe endpoint to a child without turning the parent stream itself into child-owned stdio. The parent can then reclaim unread bytes or lend the same endpoint to a later child.This is useful for bash-like partial consumption of long-lived streams. For example, a parent can keep ownership of a Server Sent Event stream while delegating bounded reads to external tools, then continue parsing from the exact byte where the child stopped.
Endpoints created by
pipe.createPipe()are rejected byspawnSync(), and an endpoint may only be leased to one child process at a time.After moving to net module, found socket pair to be a similarly untapped libuv export so included that. So now:
net.createPipe()exposes directional OS-backed endpoints:{ readable, writable }.net.createSocketPair()exposes symmetric duplex OS-backed endpoints:[left, right].stdio, because that maps cleanly to inherited pipe handles on both Unix and Windows.stdio; instead, they use Node’s existing IPC handle-transfer path withsubprocess.send(), which matches how socket-like handles already cross process boundaries.end(), consumption,resume(), ordestroy()as appropriate.net.createPipe
Child process 'sips' just a single character from the pipe leaving parent to drain what's left.
net.createSocketPair()
Child process echos parent message over a socket pair.
Thank you for considering my pull request!